<template>
  <ToolbarButton
    icon="i-ri-file-list-3-line"
    title="目录"
    :active="false"
    :large-icon="props.largeIcon"
    :hide-text="props.hideText"
    @click="insertTableOfContents"
  />
</template>

<script setup lang="ts">
import { inject, type Ref } from "vue";
import type { Editor } from "@tiptap/vue-3";
import ToolbarButton from "../../../button/index.vue";

defineOptions({
  name: "TableOfContents",
});

const props = withDefaults(
  defineProps<{
    largeIcon?: boolean;
    hideText?: boolean;
  }>(),
  {
    largeIcon: false,
    hideText: true,
  }
);

const editor = inject<Ref<Editor>>("editor");

const insertTableOfContents = () => {
  if (!editor?.value) return;

  editor.value.chain().focus().addTableOfContents().run();
};
</script>

